import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_spectrum/flutter_spectrum.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  void test() async {
    //ios添加权限
    //<key>NSUbiquitousContainers</key>
    //<dict/>
    //<key>UIFileSharingEnabled</key>
    //<true/>
    final flutterSpectrumPlugin = FlutterSpectrum();

    ///开始播放
    flutterSpectrumPlugin.startPlay(
        filePath: "",
        onEvent: (data) {},
        onError: (error) {},
        playCompleted: (state) {});

    ///停止播放
    flutterSpectrumPlugin.stopPlay();

    ///快速傅里叶
    flutterSpectrumPlugin.performFFT([]);

    ///汉明窗
    flutterSpectrumPlugin.applyHammingWindow([]);

    ///归一化
    flutterSpectrumPlugin.normalize([]);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: TextButton(
              onPressed: () {}, child: Text('Running on: $_platformVersion\n')),
        ),
      ),
    );
  }
}
